<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <meta http-equiv="X-UA-Compatible" content="ie=edge">
  <title>Vue中的JS动画与velocity.js</title>
  <script src="../asset/js/vue.js"></script>
  <script src="../asset/js/velocity.min.js"></script>
</head>

<body>
  <div id="root">
    <!-- js的出场动画 -->
    <transition name='fade' @before-enter='handleBeforeEnter' @enter='handleEnter' @after-enter='handleAfterEnter'>
      <div v-show='show'>Hello World</div>
    </transition>
    <!-- js的出场动画 -->
    <!-- <transition name='fade' @before-leave='handleBeforeEnter' @leave='handleEnter' @after-leave='handleAfterEnter'>
      <div v-show='show'>Hello World</div>
    </transition> -->
    <button @click='handleClick'>toggle</button>
  </div>
  <script>
    let vm = new Vue({
      el: '#root',
      data: {
        show: true
      },
      methods: {
        handleClick() {
          this.show = !this.show
        },
        handleBeforeEnter(el) {
          console.log('beforeEnter')
          el.style.opacity = 0;
        },
        handleEnter(el, done) {
          Velocity(el, {
            opacity: 1
          }, {
            duration: 1000,
            complete: done //动画结束，进入下一阶段
          })
        },
        handleAfterEnter(el) {
          console.log('动画结束')
        }
      }
    })
  </script>
</body>

</html>